package com.bjc.concurrent;

import java.util.concurrent.TimeUnit;

/**
 * @program: aqs_study
 * @description:
 * @author: bjc
 * @create: 2021-03-18 21:39
 */
public class VolatileVisibilityTest {

    private static volatile boolean INIT_FLAG = false;
    //private static boolean INIT_FLAG = false;

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            System.out.println("waiting data...");
            while (!INIT_FLAG){
            }
            System.out.println("===================success");
        }).start();
        TimeUnit.SECONDS.sleep(2L);
        new Thread(()->{
            prepareDate();
        }).start();
    }

    public static void prepareDate(){
        System.out.println("prepareing data start...");
        INIT_FLAG = true;
        System.out.println("prepareing data end...");
    }
}
